package com.example.yunxiappbackend.controller;

import com.example.yunxiappbackend.pojo.Article;
import com.example.yunxiappbackend.service.ArticleService;
import com.example.yunxiappbackend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;

    @GetMapping
    public Result<List<Article>> getAll(){
        List<Article> list = articleService.list();
        return Result.success(list);
    }
    @GetMapping("/{id}")
    public Result<Article> getArticleById(@PathVariable("id") String id) {
        Article a = articleService.getById(id);
        return Result.success(a);
    }
}
